﻿using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.CultureSwitcher.Models;
using Orchard.Data;
using Orchard.Environment.Extensions;
using Orchard.Localization;

namespace Orchard.CultureSwitcher.Handlers
{
    public class SwitcherSettingsHandler : ContentHandler
    {
        public const string SETTINGS_GROUP_ID = "SwitcherSettings";

        public SwitcherSettingsHandler(IRepository<SwitcherSettingsPartRecord> switcherSettingsPartRepository)
        {
            Filters.Add(StorageFilter.For(switcherSettingsPartRepository));
            Filters.Add(new ActivatingFilter<SwitcherSettingsPart>("Site"));
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        protected override void GetItemMetadata(GetContentItemMetadataContext context)
        {
            if (context.ContentItem.ContentType != "Site") return;

            base.GetItemMetadata(context);

            var groupInfo = new GroupInfo(T("Culture Switcher Settings"))
            {
                Id = SETTINGS_GROUP_ID,
                Position = "1"
            };
            context.Metadata.EditorGroupInfo.Add(groupInfo);
        }
    }
}